﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using ExtBusiness;
using WF_Business;

namespace ExtBusiness.PubInfo
{
    /// <summary>
    /// 
    /// </summary>
    public class ContentInfoManage
    {
        /// <summary>
        /// 根据用户获取信息
        /// </summary>
        /// <param name="Type"></param>
        /// <param name="strUserid"></param>
        /// <returns></returns>
        public DataTable GetInfoByUser(string Type, string strUserid)
        {
            string strSql = @"select t.id as id,(case when length(t.title)>14 then 
                Substr(t.title,0,14) || '...' else t.title end ) as title,t.time,t.type  
                from st_other t where 1 = 1  ";
            if (!string.IsNullOrEmpty(Type))
            {
                strSql += string.Format(" and type ='{0}'", Type);
            }
            if (!string.IsNullOrEmpty(strUserid))
            {
                strSql += string.Format(" and userid ='{0}'", strUserid);
            }
            strSql += " order by t.time desc";

            DataTable dtTemp = new DataTable();
            SysParams.OAConnection().RunSql(strSql, out dtTemp);
            return dtTemp;
        }

        /// <summary>
        /// 读取办事指南内容
        /// </summary>
        /// <param name="strContentType">办事指南类别</param>
        /// <param name="strWid">获取流程id</param>
        /// <returns></returns>
        public DataTable GetPubContentInfo(string strContentType, string strWid)
        {
            string strSql = string.Format(@"select * from ST_OTHER where type='{0}' and 
            SMALLTYPE=(select wname from st_workflow a where a.wid='{1}')",
                strContentType, strWid);

            DataTable dtTemp = new DataTable();
            SysParams.OAConnection().RunSql(strSql, out dtTemp);
            return dtTemp;
        }

        /// <summary>
        /// Gets the pub content info.
        /// </summary>
        /// <param name="strContentType">Type of the STR content.</param>
        /// <param name="strWid">The STR wid.</param>
        /// <param name="strTitle">The STR title.</param>
        /// <param name="strQssj">The STR QSSJ.</param>
        /// <param name="strZzsj">The STR ZZSJ.</param>
        /// <returns></returns>
        public DataTable GetPubContentInfo(string strContentType, string strWid,
            string strTitle,string strQssj,string strZzsj)
        {
            string strSql = string.Format(@"select * from ST_OTHER where type='{0}' and 
            SMALLTYPE=(select wname from st_workflow a where a.wid='{1}') ",
                strContentType, strWid);

            if (!string.IsNullOrEmpty(strTitle))
            {
                strSql += string.Format(" and title like '%{0}%'",strTitle);
            }
            if (!string.IsNullOrEmpty(strQssj))
            {
                strSql += string.Format(" and time>=to_date('{0}','yyyy-mm-dd')", strQssj);
            }
            if (!string.IsNullOrEmpty(strZzsj))
            {
                strSql += string.Format(" and time<=to_date('{0}','yyyy-mm-dd')", strZzsj);
            }

            DataTable dtTemp = new DataTable();
            SysParams.OAConnection().RunSql(strSql, out dtTemp);
            return dtTemp;
        }

        /// <summary>
        /// Gets the pub info.
        /// </summary>
        /// <param name="strId">The STR id.</param>
        /// <returns></returns>
        public DataTable GetPubInfoById(string strId)
        {
            string strSql = @"select * from st_other t where 1 = 1  ";
            if (!string.IsNullOrEmpty(strId))
            {
                strSql += string.Format(" and id ='{0}'", strId);
            }

            DataTable dtTemp = new DataTable();
            SysParams.OAConnection().RunSql(strSql, out dtTemp);
            return dtTemp;
        }

        /// <summary>
        /// 读取办事指南内容
        /// </summary>
        /// <param name="strWid">流程名称</param>
        /// <returns></returns>
        /// <!--addby zhongjian 20100118-->
        public DataTable GetPubContentInfo(string strWid)
        {
            string strSql = string.Format(@"select id,filename,flowid,ftitle,fcontent,forder
                                  from xt_lawguide
                                 where filename = (select wname from st_workflow where wid='{0}') order by forder", strWid);

            DataTable dtTemp = new DataTable();
            SysParams.OAConnection().RunSql(strSql, out dtTemp);
            return dtTemp;
        }
    }
}
